//
//  YD_getAsks_sendGiftCell.m
//  SpeedDating
//
//  Created by isu on 17/1/16.
//  Copyright © 2017年 isu. All rights reserved.
//

#import "GiftgetAsksCell.h"
#import "UIView+SDAutoLayout.h"
#import "UITableView+SDAutoTableViewCellHeight.h"
#import "GifgAnswersView.h"

#import "YD_getCurrentResponseVCTool.h"


@interface GiftgetAsksCell(){
    UILabel *_askLab;
    UIImageView *_imgV;
    UIView *_lineV;
    GifgAnswersView *_answerV;
    UIButton*_btn;
}
@end

@implementation GiftgetAsksCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self setUp];
        self.layer.borderWidth = 0.5f;
        self.layer.borderColor = [UIColor colorWithWhite:0.702 alpha:1.000].CGColor;
        self.layer.cornerRadius = 10.0f;
        self.layer.masksToBounds = YES;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

-(void)setUp{
    UIView *contentV =  self.contentView;
    UILabel *askLab = [UILabel new];
    askLab.numberOfLines = 0;
    _askLab = askLab;
    
    UIImageView *imagV = [UIImageView new];
    _imgV = imagV;
    
    GifgAnswersView *av= [[GifgAnswersView alloc]init];
    _answerV = av;
    
    UIView *lineV = [UIView new];
    lineV.backgroundColor = [UIColor lightGrayColor];
    _lineV = lineV;
    
    UIButton *btn = [UIButton new];
    [btn setTitle:@"选TA" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    _btn = btn;
    [btn addTarget:self action:@selector(choose) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView sd_addSubviews:@[_askLab,_imgV,_answerV,_lineV,_btn]];
    
    _askLab.sd_layout
    .leftSpaceToView(contentV,10)
    .topSpaceToView(contentV,10)
    .rightSpaceToView(contentV,40)
    .autoHeightRatio(0);
    
    _imgV.sd_layout
    .leftSpaceToView(contentV,10)
    .rightSpaceToView(contentV,40)
    .topSpaceToView(_askLab,10)
    .heightIs((contentV.size.width-20)*3.0/4);
    
    _answerV.sd_layout
    .leftEqualToView(_askLab)
    .rightEqualToView(_askLab)
    .topSpaceToView(_imgV,10);
    
    _lineV.sd_layout
    .leftEqualToView(contentV)
    .rightSpaceToView(contentV,15)
    .topSpaceToView(_answerV,10)
    .heightIs(0.5);
    
    _btn.sd_layout
    .leftEqualToView(_imgV)
    .rightEqualToView(_imgV)
    .topSpaceToView(_lineV,10)
    .heightIs(40);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

-(void)setQuestionModel:(GiftAskinterViewModel *)questionModel{
    _questionModel = questionModel;
    _askLab.text = questionModel.ask;
    if(questionModel.img.length>0){
        [_imgV sd_setImageWithURL:[NSURL URLWithString:HttpImgUrl(questionModel.img)] placeholderImage:[UIImage imageNamed:@"llustration"]];
    }else{
        _imgV.sd_layout
        .heightIs(0)
        .topSpaceToView(_askLab,0);
    }
    NSArray *arr = [questionModel.answer componentsSeparatedByString:@","];
    _answerV.answersArr =arr;
    [self setupAutoHeightWithBottomView:_btn bottomMargin:10];
}

-(void)choose{
    //开始送礼物
    [HcardHttpmanager giveGiftWithWid:[NSString stringWithFormat:@"%@",self.info.uid] WithGiftId:[NSString stringWithFormat:@"%ld",(long)self.sendModel.giftId] WithStatus:@"1" WithAskId:_questionModel.askId Success:^(id result) {
        if(result){
            [SVProgressHUD showSuccessWithStatus:@"礼物赠送成功"];
   
        }
        else{
           
        }
    } failure:^(NSError *error) {

    }];

}
@end
